home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_10 / 2n10038a < prev    next >
Text File  |  1991-08-25  |  35KB  |  1,197 lines

  1.     Page    60,132
  2. ;---------------------------------------------------------------
  3. ;               BEGIN LISTING 2
  4. ;---------------------------------------------------------------
  5. ;
  6. ; 386LOAD.ASM    Copyright (c) 1991 Robert Collins
  7. ;
  8. ;    This program demonstrates various aspects of CPU
  9. ;    behavior that become apparent when using LOADALL.
  10. ;
  11. ;    Test 1:  Checks that LOADALL loads all the general-
  12. ;         purpose registers; loads the segment registers
  13. ;         with values that are inconsistant to their
  14. ;         respective descriptor cache registers.
  15. ;
  16. ;    Test 2:  Access extended memory in real mode.
  17. ;
  18. ;    Test 3:  Tests that the Present bit in a descriptor
  19. ;         table can be loaded using LOADALL without
  20. ;         generating exception 11.  But when the segment
  21. ;         is accessed, exception 13 is generated.
  22. ;         NOTE:    This test should be done in protected
  23. ;         mode, but can be done in real mode.  1) In real
  24. ;         mode, no error code is pushed on the stack
  25. ;         (possibly due to a bug in the CPU).  2) Also,
  26. ;         when this test is executed in real-mode, the
  27. ;         '386 fails to set the Present bit when the
  28. ;         segment is subsequently loaded.  This latter
  29. ;         condition is clearly a bug in the '386.
  30. ;
  31. ;    Test 4:  Test 32-bit protected mode.
  32. ;
  33. ;    Test 5:  Test 32-bit real mode -- a mode that is an
  34. ;         illegal mode for the CPU.
  35. ;
  36. ;    Test 6:  Test that the Granularity bit in the descriptor
  37. ;         cache register has no affect on the segment
  38. ;         limit field.
  39. ;
  40. ;    Test 7:  Test execution breakpoints.
  41. ;
  42. ;    Test 8:  Test data breakpoints.
  43. ;
  44. ;    This program was written for Microsoft MASM 5.1.
  45. ;    This program contains compiler directives and branching
  46. ;    techniques that might not be available on previous
  47. ;    versions of the Macro Assembler, nor in competitive
  48. ;    products.
  49. ;
  50. ;---------------------------------------------------------------
  51.  
  52. ;---------------------------------------------------------------
  53. ; Compiler directives
  54. ;---------------------------------------------------------------
  55.     Title    LOADALL_386
  56.     .radix    16
  57.     .8086
  58.  
  59.  
  60. ;---------------------------------------------------------------
  61. ; Interrupt vector segment
  62. ;---------------------------------------------------------------
  63. ABS0    segment at 0
  64.     org 6*4
  65.     INT_6        dd    ?
  66. ABS0    ends
  67.  
  68.  
  69. ;---------------------------------------------------------------
  70. ; Structure definitions
  71. ;---------------------------------------------------------------
  72. Desc_cache    STRUC
  73.         db    0
  74.     _Type    db    ?
  75.     _CS32    db    0
  76.         db    0
  77.     _Addr    dd    ?
  78.     _Limit    dd    ?
  79. Desc_cache    ENDS
  80.  
  81.  
  82. Loadall_struc    STRUC
  83.     _Cr0        dd    0
  84.     _Eflags     dd    2
  85.     _Eip        dd    0
  86.     _Edi        dd    66666666h
  87.     _Esi        dd    77777777h
  88.     _Ebp        dd    55555555h
  89.     _Esp        dd    88888888h
  90.     _Ebx        dd    22222222h
  91.     _Edx        dd    44444444h
  92.     _Ecx        dd    33333333h
  93.     _Eax        dd    11111111h
  94.     _Dr6        dd    0
  95.     _Dr7        dd    0
  96.     _Tr        dd    0
  97.     _Ldt        dd    0
  98.     _Gs        dd    5555h
  99.     _Fs        dd    4444h
  100.     _Ds        dd    2222h
  101.     _Ss        dd    6666h
  102.     _Cs        dd    1111h
  103.     _Es        dd    3333h
  104.     TSS_Desc    dd    00008900h,00070000h,00000800h
  105.     IDT_Desc    dd    00000000h,00000000h,000003ffh
  106.     Gdt_Desc    dd    00000000h,00000000h,00000000h
  107.     Ldt_Desc    dd    00008200h,00090000h,00000088h
  108.     GS_Desc     dd    00009300h,00050000h,0000ffffh
  109.     FS_Desc     dd    00009300h,00040000h,0000ffffh
  110.     DS_Desc     dd    00009300h,00020000h,0000ffffh
  111.     SS_Desc     dd    00009300h,00060000h,0000ffffh
  112.     CS_Desc     dd    00009b00h,00000000h,0000ffffh
  113.     ES_Desc     dd    00009300h,00030000h,00fffffch
  114. Loadall_Struc    ENDS
  115.  
  116.  
  117. Descriptor  STRUC
  118.     Seg_limit        dw        ?        ; Segment limit
  119.     Base_A15_A00    dw        ?        ; A00..A15 of base address
  120.     Base_A23_A16    db        ?        ; A16..A23 of base address
  121.     Access_rights   db        ?        ; Segment access rights
  122.     Limit_A19_A16   db        ?        ; Granularity, Op-size,
  123.                     ;  Limit A16..A19
  124.     Base_A31_A24    db        ?        ; A24..A31 of base address
  125. Descriptor  ENDS
  126.  
  127.  
  128. INT_Desc    STRUC
  129.     IGate_Offset    dw        ?        ; Offset of handler
  130.     CSEG_Sel        dw        ?        ; Code segment selector
  131.             db        0
  132.             db        86h     ; 286 interrupt gate=16bit
  133.                     ;  CS:IP, FLAGS
  134.     Resvd        dw        0        ; Reserved=0
  135. INT_Desc    ENDS
  136.  
  137.  
  138. ;-----------------------------------------------------------------------------
  139. ; Macro definitions
  140. ;-----------------------------------------------------------------------------
  141.     Init_descriptor    macro   segment,offset,desc_name
  142.     push    ax
  143.     push    dx
  144.     push    si
  145.     push    es
  146.     mov    ax,&segment        ;; get segment name
  147.     mov    es,ax            ;;   to form 24 bit address
  148.     mov    si,&offset        ;;
  149.     mov    ax,es            ; point to control block
  150.     xor    dh,dh            ; clear upper register
  151.     mov    dl,ah            ; build high byte of 32-bit address
  152.     shr    dl,4            ; use only high nibble from (AX)
  153.     shl    ax,4            ; strip high nibble from segment
  154.     add    ax,si            ; add the GDT offset to develop low word
  155.     adc    dx,0            ; adjust high byte if carry from low
  156.     mov    &desc_name.Base_A15_A00,ax    ;; low word of address
  157.     mov    &desc_name.Base_A23_A16,dl    ;; high byte of address
  158.     mov    &desc_name.Base_A31_A24,dh    ;; high byte of linear address
  159.     pop    es
  160.     pop    si
  161.     pop    dx
  162.     pop    ax
  163.     endm
  164.  
  165.  
  166. FARJMP    MACRO    destination,selector    ; dynamic JMP FAR SEG:OFF
  167.     db    0eah            ;; jmp instruction
  168.     dw    offset destination    ;; offset word
  169.     dw    selector        ;; segment selector word
  170.     endm
  171.  
  172.  
  173. LONGJMP MACRO    destination,selector    ; dynamic JMP FAR SEG:OFF
  174.     db    0eah            ;; jmp instruction
  175.     dd    offset destination    ;; offset word
  176.     dw    selector        ;; segment selector word
  177.     endm
  178.  
  179.  
  180. IO_DELAY    MACRO
  181.     out    0edh,ax
  182.     endm
  183.  
  184. LOADALL     MACRO
  185.     db    0fh,07h
  186.     ENDM
  187.  
  188.  
  189. PRINT_STRING    MACRO    MSG_NAME
  190.     mov    ah,9
  191.     mov    dx,offset MSG_NAME
  192.     int    21h
  193.     ENDM
  194.  
  195.  
  196.     _DATA     SEGMENT PARA PUBLIC 'DATA'
  197. ;---------------------------------------------------------------
  198. ; Equates & local variables
  199. ;---------------------------------------------------------------
  200. ; Protected mode access rights
  201. ;---------------------------------------------------------------
  202.     CS_access    equ    10011011b
  203.     DS_access    equ    10010011b
  204.  
  205. ;---------------------------------------------------------------
  206. ; Text equates
  207. ;---------------------------------------------------------------
  208.     CRLF        equ    <0dh,0ah>
  209.     CRLF$        equ    <CRLF,'$'>
  210.     INT6        equ    [bp-4]
  211.  
  212. ;---------------------------------------------------------------
  213. ; Loadall table(s)
  214. ;---------------------------------------------------------------
  215.     Loadall_tbl    Loadall_struc <>
  216.     Machine_State    Loadall_struc <>
  217.  
  218. ;---------------------------------------------------------------
  219. ; Global Descriptor Table
  220. ;---------------------------------------------------------------
  221.     GDT_386 Descriptor    <Gdt3_len-1,,,DS_access>
  222.     CSEG3    Descriptor    <0ffffh,0,0,CS_access>
  223.     DSEG3    Descriptor    <0ffffh,0,20h,DS_access>
  224.     Gdt3_len      equ    $-Gdt_386
  225.  
  226. ;---------------------------------------------------------------
  227. ; Interrupt Descriptor Table
  228. ;---------------------------------------------------------------
  229. IDT_386 INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT00
  230.     INT_Desc    <Offset INT01,CSEG3-GDT_386>    ; INT01
  231.     INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT02
  232.     INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT03
  233.     INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT04
  234.     INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT05
  235.     INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT06
  236.     INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT07
  237.     INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT08
  238.     INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT09
  239.     INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT0a
  240.     INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT0b
  241.     INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT0c
  242.     INT_Desc    <Offset INT13,CSEG3-GDT_386>    ; INT0d
  243. IDT3_Len    equ    $-IDT_386
  244.  
  245. ;---------------------------------------------------------------
  246. ; Misc. local variables
  247. ;---------------------------------------------------------------
  248.     Mem_buffer    db    400h dup (0)    ; Store 2M mem.
  249.     Buffer        db    40h dup (0)
  250.     Buffer2     dw    10h dup (0)
  251.  
  252.     RM_IDT3_Ptr    dw    (256d*4)-1    ; Real-mode IDT
  253.             dd    0        ;  pointer
  254.             dw    0
  255.  
  256.  
  257. ;---------------------------------------------------------------
  258. ; String Messages
  259. ;---------------------------------------------------------------
  260. Passed    db    "    PASSED.",CRLF$
  261. Failed    db    "--> FAILED <--",CRLF$
  262. Not_386 db    "Not 80386 class computer.",CRLF$
  263. Rmvd    db    "LOADALL removed from 80386 mask.",CRLF$
  264. RFail    db    "Registers weren't loaded correctly."
  265. LF    db     CRLF$
  266.  
  267. ;